import 'package:common/utils/display_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:user/mvp/view/login_page.dart';

class LoginPageBody {
  final TextEditingController _userNameController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();

  Widget createBody(BuildContext context, OnLogin onLogin) {
    ///保障房业务端账号
    _userNameController.text = "admin";
    _passwordController.text = "a123456";
    final ButtonStyle style = ElevatedButton.styleFrom(
        foregroundColor: Colors.white,
        backgroundColor: Colors.blue,
        textStyle: const TextStyle(fontSize: 20));
    return SingleChildScrollView(
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: [
          Container(
            color: Colors.white,
            height: DisplayUtil.getScreenHeight(context),
          ),
          const Positioned(
              left: 20,
              top: 60,
              child: Image(
                height: 20,
                width: 20,
                image: AssetImage("assets/images/xxhdpi/close.png", package: "resource"),
              )),
          const Positioned(
              left: 0,
              right: 0,
              top: 80,
              child: Image(
                height: 80,
                width: 80,
                image: AssetImage("assets/images/xxhdpi/login_logo.png", package: "resource"),
              )),
          Positioned(
              left: 40,
              right: 40,
              top: 170,
              child: TextField(
                  controller: _userNameController,
                  inputFormatters: [
                    LengthLimitingTextInputFormatter(11),
                    FilteringTextInputFormatter.digitsOnly,
                  ],
                  maxLines: 1,
                  maxLength: 11,
                  decoration: const InputDecoration(
                    icon: Icon(
                      Icons.mobile_screen_share_rounded,
                      color: Colors.blue,
                    ),
                    labelText: "用户名",
                    hintText: "请输入用户名",
                  ),
                  keyboardType: TextInputType.number)),
          Positioned(
              left: 40,
              right: 40,
              top: 250,
              child: TextField(
                  controller: _passwordController,
                  obscureText: true,
                  maxLines: 1,
                  decoration: const InputDecoration(
                    icon: Icon(Icons.lock, color: Colors.blue),
                    labelText: "密码",
                    hintText: "请输入密码",
                  ),
                  keyboardType: TextInputType.number)),
          Positioned(
              right: 40,
              top: 270,
              child: TextButton(
                onPressed: () {},
                child: const Text('忘记密码？', style: TextStyle(fontSize: 14, color: Colors.blue)),
              )),
          Positioned(
              top: 370,
              child: TextButton.icon(
                style: const ButtonStyle(enableFeedback: false),
                icon: const Image(
                  height: 20,
                  width: 20,
                  image: AssetImage("assets/images/xxhdpi/red_bonus.png", package: "resource"),
                ),
                label:
                const Text("还没有账号，去注册 >", style: TextStyle(fontSize: 14, color: Colors.blue)),
                onPressed: () {},
              )),
          Positioned(
              left: 50,
              right: 50,
              top: 490,
              child: ElevatedButton(
                style: style,
                onPressed: () {
                  onLogin(_userNameController.text,_passwordController.text);
                },
                child: const Text('登录'),
              )),
          const Positioned(
              bottom: 0,
              right: 0,
              left: 0,
              child: Image(
                image: AssetImage("assets/images/xxhdpi/bg_login_bottom.png", package: "resource"),
              )),
        ],
      ),
    );
  }
}
